package com.echo.yixiaowu.feature.main.home

import androidx.annotation.ColorRes
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState
import androidx.compose.runtime.Immutable
import com.echo.yixiaowu.feature.player.FetchBackendDataUiState
import kotlinx.serialization.Serializable

@Serializable
data class DraggableItem(
    val id: Int,
    val title: String,
    val isSelect: Boolean,
    val tabSelectedPage: Int = 0,
    @ColorRes val background: Int,
    val tabs: List<HomeTabItem>
)

@Serializable
data class HomeTabItem(
    val id: Int,
    val title: String
)

/**
 * UI状态 (State)
 * @param items 当前列表项的顺序
 * @param isLoading 初始加载时是否显示加载中状态
 */
@Immutable
data class SortState(
    val items: List<DraggableItem> = emptyList(),
    val selectedItemId: Int = 1,
    val isLoading: Boolean = true,
    val listStates: List<LazyListState> = emptyList(),
    val innerGridStates: MutableMap<Int, List<LazyStaggeredGridState>> = mutableMapOf(),
)

@Immutable
data class RecommendItem(
    val id: String,
    val userName: String,
    val userDetail: String,
    // 预留 头像
    val userAvatar: String,
    // 预留 媒体或图文
    val type: String,
    val url: List<String>,
    val description: String
)

@Immutable
data class RecommendState(
    val fetchBackendDataUiState: FetchBackendDataUiState = FetchBackendDataUiState(),
    val recommendList: List<RecommendItem> = emptyList()
)

/**
 * 用户事件 (Event / Intent)
 * 封装了所有可能的用户操作
 */
sealed interface HomeEvent {
    data class OnSaveChanges(val menuItems: List<DraggableItem>) : HomeEvent
    data class OnItemSelected(val itemId: Int) : HomeEvent
    data class OnTabSelected(val pageId: Int, val tabId: Int) : HomeEvent
    data class OnLoadTabData(val userId: Int, val tabId: Int, val isUserExecute: Boolean) : HomeEvent
}

/**
 * 副作用 (Effect / Single-time Event)
 * 用于处理导航、Toast、SnackBar等一次性事件
 */
sealed interface SortEffect {
    data class ShowToast(val message: String) : SortEffect
}